package com.esoon.controller;

import com.esoon.service.CsrAgentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName LastAgentController
 * @Description TODO agent : 正常情况下为坐席工号，查询不到的情况下为0
 * @Author 2020/9/28 12:08
 * @Version 1.0
 **/

@RestController
@RequestMapping("/v1/LastAgent")
public class LastAgentController {
    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(LastAgentController.class);
    }
    @Resource
    private CsrAgentService csrAgentService;

    @RequestMapping(value = "/getLastAgent", method = RequestMethod.GET)
    public String getLastAgent(@RequestParam String phone , @RequestParam String tenantCode) {
        logger.info("invoking lastAgent interface , the url = '/v1/lastAgent/getLastAgent' , the requestParam : phone = [{}] , tenantCode = [{}]"
        ,phone , tenantCode);
        String agentCode = "";
        try {
            agentCode = csrAgentService.selectLastAgent(phone,tenantCode);
           if (agentCode == null || agentCode.isEmpty()){
               agentCode = "0";
           }
        } catch (Exception e) {
            logger.error(e.toString());
            return "500";
        }
        return agentCode;
    }
}
